﻿YAHOO.example.init = function () {
    function onButtonClick(p_oEvent) {
        switch (this.get("id")) {
            case "btnSave":
                Save();
                break;
            case "btnSave1":
                Save1(0);
                break;
            case "btnBack":
                YAHOO.example.container.dialog3.show();
                break;
            case "btnClose":
                Close();
                break;
            case "btnNew1":
                handleAdd();
                break;
            case "btnDelete1":
                handleDelete();
                break;
            default:
                break;
        }
    }
    YAHOO.util.Event.onContentReady("toolbar", function () {
        btnSave = new YAHOO.widget.Button("btnSave");
        btnSave.on("click", onButtonClick);
        btnSave1 = new YAHOO.widget.Button("btnSave1");
        btnSave1.on("click", onButtonClick);
        btnBack = new YAHOO.widget.Button("btnBack");
        btnBack.on("click", onButtonClick);
        btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
        if (flag == "0") { //新增时设置按钮隐藏
            btnSave1._button.style.display = "none";
            $("#btnSave1").attr('disabled', "true");
            btnBack._button.style.display = "none";
            $("#btnBack").attr('disabled', "true");
        }
        if (flag == "1" && view != "" && OperStatus == "1") { //退回时允许修改信息
            btnSave1._button.style.display = "none";
            $("#btnSave1").attr('disabled', "true");
            btnBack._button.style.display = "none";
            $("#btnBack").attr('disabled', "true");
            setControlDisabled(2);
            LoadOrderProductInfo($("#OrderID").val());
            LoadPayAccount($("#OrderProductID").val());
            vi = DeliverMajorInfo.length;
        }
        if (flag == "2") {  //变更
            btnSave1._button.style.display = "none";
            $("#btnSave1").attr('disabled', "true");
            btnBack._button.style.display = "none";
            $("#btnBack").attr('disabled', "true");
            setControlDisabled(2);
            LoadOrderProductInfo($("#OrderID").val());
            LoadPayAccount($("#OrderProductID").val());
        }
        if (view == "check") {
            btnSave._button.style.display = "none";
            $("#btnSave").attr('disabled', "true");
            btnSave1._button.style.display = "none";
            $("#btnSave1").attr('disabled', "true");
            btnBack._button.style.display = "none";
            $("#btnBack").attr('disabled', "true");
            setControlDisabled(1);
            LoadOrderProductInfo($("#OrderID").val());
            LoadPayAccount($("#OrderProductID").val());
        }
    });
    YAHOO.util.Event.onContentReady("con_two_1", function () {
        btnNews1 = new YAHOO.widget.Button("btnNew1");
        btnNews1.on("click", onButtonClick);
        btnDeletes1 = new YAHOO.widget.Button("btnDelete1");
        btnDeletes1.on("click", onButtonClick);
        if (flag == "1" && view == "") { //确认时设置按钮隐藏
            btnSave._button.style.display = "none";
            $("#btnSave").attr('disabled', "true");
            btnNews1._button.style.display = "none";
            $("#btnNews1").attr('disabled', "true");
            btnDeletes1._button.style.display = "none";
            $("#btnDeletes1").attr('disabled', "true");
            setControlDisabled(1);
            LoadOrderProductInfo($("#OrderID").val());
            LoadPayAccount($("#OrderProductID").val());
        }
        if (view == "check") {
            btnNews1._button.style.display = "none";
            $("#btnNews1").attr('disabled', "true");
            btnDeletes1._button.style.display = "none";
            $("#btnDeletes1").attr('disabled', "true");
        }
    });
} ();
/* 对应的方法和ID*/
var _fn, _id;
function ShowDialog(fn, id, src) {
    _fn = fn;
    _id = id;
    document.getElementById("EditUIWindow1").src = src;
    YAHOO.example.container.dialog1.show();
}
//业绩归属选择对应的方法和ID
var _fn, _id;
function ShowDialog2(fn, id) {
    _fn = fn;
    _id = id;
    YAHOO.example.container.dialog2.show();
}
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
    var handleSubmit = function () {
        var editwindow = document.getElementById("EditUIWindow1");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
            if (_id == "btnOrderID") {
                LoadOrderInfo();
            } else if (_id == "btnProductLayoutID") {
                LoadProductLayout();
            }
        }
        YAHOO.example.container.dialog1.hide();
    };
    var handleSubmit2 = function () {
        var editwindow = document.getElementById("EditUIWindow2");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
        }
        YAHOO.example.container.dialog2.hide();
    }
    var handleSubmit3 = function () {
        Back();
    }
    var handleCancel = function () {
        this.cancel();
    };
    var handleSuccess = function (o) {
        var response = o.responseText;
        response = response.split("<!")[0];
        document.getElementById("resp").innerHTML = response;
    };
    var handleFailure = function (o) {
        alert("Submission failed: " + o.status);
    };
    YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
					        { width: "620px",
					            height: "460px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            close: true,
                                modal:true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "确定", handler: handleSubmit, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
					        { width: "300px",
					            height: "400px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            close: true,
					            modal: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "确定", handler: handleSubmit2, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
	YAHOO.example.container.dialog3 = new YAHOO.widget.Dialog("dialog3",
					        { width: "400px",
					            height: "200px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            close: true,
					            modal: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "确定", handler: handleSubmit3, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
    YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
    YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
    YAHOO.example.container.dialog3.render();
    //拖动大小1
    var resize = new YAHOO.util.Resize("dialog1", {
        handles: ["br"],
        autoRatio: false,
        minWidth: 450,
        minHeight: 300,
        status: false
    });
    resize.on("startResize", function (args) {
        if (this.cfg.getProperty("constraintoviewport")) {
            var D = YAHOO.util.Dom;

            var clientRegion = D.getClientRegion();
            var elRegion = D.getRegion(this.element);

            resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
        } else {
            resize.set("maxWidth", null);
            resize.set("maxHeight", null);
        }

    }, YAHOO.example.container.dialog1, true);
    resize.on("resize", function (args) {
        var panelHeight = args.height;
        this.cfg.setProperty("height", panelHeight + "px");
    }, YAHOO.example.container.dialog1, true);
    //拖动大小2
    var resize = new YAHOO.util.Resize("dialog2", {
        handles: ["br"],
        autoRatio: false,
        minWidth: 300,
        minHeight: 250,
        status: false
    });
    resize.on("startResize", function (args) {
        if (this.cfg.getProperty("constraintoviewport")) {
            var D = YAHOO.util.Dom;

            var clientRegion = D.getClientRegion();
            var elRegion = D.getRegion(this.element);

            resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
        } else {
            resize.set("maxWidth", null);
            resize.set("maxHeight", null);
        }

    }, YAHOO.example.container.dialog2, true);
    resize.on("resize", function (args) {
        var panelHeight = args.height;
        this.cfg.setProperty("height", panelHeight + "px");
    }, YAHOO.example.container.dialog2, true);
});
//根据订单产品ID获取订单信息
var LoadOrderInfo = function () {
    var vCId = "ID='" + $("#OrderID").val() + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmCustomerInfoDeliver&customCondition=" + vCId + "",
    { success: function (res) {
        try {
            var str = res.responseText;
            var arr = [];
            var obj = eval(str);
            $('#CustomerId').val(obj[0].CustomerId);
            $('#CustomerName').val(obj[0].CustomerName);
            $('#CustomerSource').val(obj[0].OriginName);
            $('#Account').val("");
            $('#Pay1').val("");
            $('#Pay2').val("");
            document.getElementById("ProductList").options.length = 0;
            LoadOrderProductInfo(obj[0].ID);
        } catch (e) {
        }
        finally {
        }
    }, failure: function () { }
    });
}
var tempProduct = "";
var LoadOrderProductInfo = function (OrderId) {
    var vCId = "OrderID='" + OrderId + "' and PhraseID='9b1639ba-d3fd-4f1c-bab2-12fedbc8b30d' and ProductName not like '%" + encodeURI("内训") + "%'"; //加载属于大课的产品
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_DeliverOrderProduct&customCondition=" + vCId + "",
    { success: function (res) {
        try {
            var str = res.responseText;
            var arr = [];
            var obj = eval(str);
            tempProduct = obj;
            document.getElementById("ProductList").options.length = 0;
            $("#ProductList").append("<option value=''> </option>");
            var vOrderProductId = $("#OrderProductID").val();
            for (var i = 0; i < obj.length; i++) {
                if (vOrderProductId == obj[i].ID) {
                    $("#ProductId").val(obj[i].ProductId);
                    $("#ProductList").append("<option value='" + obj[i].ID + "' selected>" + obj[i].ProductName + "</option>");
                    $('#Account').val(tempProduct[i].Amount);
                    $('#Pay1').val(tempProduct[i].AccountReceivable);
                    $('#Pay2').val(tempProduct[i].AccountReceivable - tempProduct[i].ResignMoney);
                } else {
                    $("#ProductList").append("<option value='" + obj[i].ID + "'>" + obj[i].ProductName + "</option>");
                }
            }
        }
        catch (e) {
        }
        finally {
        }
    }, failure: function () { }
    });
}
if (typeof ($) != "undefined") {
    $(document).ready(function () {
        $('#ProductList').change(function () {
            var OptionValue = $(this).children('option:selected').val();
            if (OptionValue != "") {
                for (var i = 0; i < tempProduct.length; i++) {
                    if (tempProduct[i].ID == OptionValue) {
                        $("#OrderProductID").val(tempProduct[i].ID);
                        $("#ProductId").val(tempProduct[i].ProductId);
                        $('#Account').val(tempProduct[i].Amount);
                        $('#Pay1').val(tempProduct[i].AccountReceivable);
                        $('#Pay2').val(tempProduct[i].AccountReceivable - tempProduct[i].ResignMoney);
                        //加载已交付数量
                        LoadPayAccount(tempProduct[i].ID);
                    }
                }
            } else {
                $('#Account').val("");
                $('#Pay1').val("");
                $('#Pay2').val("");
            }
        });
        if (flag == "1" || flag == "2") {
            $("#ClassNumber").val(DeliverMajorInfo.length); //上课人数
        }
    })
}
//加载已交付数量
var LoadPayAccount = function (OrderProductId) {
    var SaveUrl = "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&action=check&entity=CrmDeliverMajorPayAccount&id=" + OrderProductId;
    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "00") {
                    alert("加载已交付数量异常!");
                    return;
                } else {
                    $("#PayAccount").val(str);
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}
//根据产品规划ID获取产品规划信息
var LoadProductLayout = function () {
    var vPId = "ID='" + $("#ProductLayoutID").val() + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=CrmProductLayout&customCondition=" + vPId + "",
    { success: function (res) {
        try {
            var str = res.responseText;
            var arr = [];
            var obj = eval(str);
            $('#Date').val(obj[0].BeginDate + "-- " + obj[0].EndDate);
            $('#Address').val(obj[0].Place);
        }
        catch (e) {
        }
        finally {
        }
    }, failure: function () { }
    });
}


var format1 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null) {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='ClassName' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='ClassName' size='50' maxlength='50' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='ClassName' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' name='ClassName' size='50' maxlength='50' style='width:95%;'>";
        }
    }
}
var format2 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' size='18' maxlength='18' name='IDCard' style='width:95%;'>";
        }
    }
}
var format3 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='Sex' style='width:95%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='Sex' style='width:95%;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='男'>男</option>");
        str1.push("<option value='女'>女</option>");
    } else {
        if (sData == "男") {
            str1.push("<option value='男' selected>男</option>");
            str1.push("<option value='女'>女</option>");
        } else {
            str1.push("<option value='女' selected>女</option>");
            str1.push("<option value='男'>男</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format4 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null) {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='Post' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='Post' size='10' maxlength='10' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='Post' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' name='Post' size='10' maxlength='10' style='width:95%;'>";
        }
    }
}
var format5 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='IsDecision' style='width:70px;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='IsDecision' style='width:70px;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='0'>否</option>");
        str1.push("<option value='1'>是</option>");
    } else {
        if (sData == "1") {
            str1.push("<option value='1' selected>是</option>");
            str1.push("<option value='0'>否</option>");
        } else {
            str1.push("<option value='0' selected>否</option>");
            str1.push("<option value='1'>是</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format6 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null) {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' size='10' maxlength='10' name='ArriveatTime' style='width:95%;'>";
        }
    }
}
var format7 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='HouseType' style='width:100%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='HouseType' style='width:100%;'>");
    }
    str1.push("<option value='00'> </option>");
    for (var i = 0; i < HouseType.length; i++) {
        if (HouseType[i].PhraseID == sData) {
            str1.push("<option value='" + HouseType[i].PhraseID + "' selected>" + HouseType[i].PhraseText + "</option>");
        } else {
            str1.push("<option value='" + HouseType[i].PhraseID + "'>" + HouseType[i].PhraseText + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format8 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='TrafficType' style='width:100%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='TrafficType' style='width:100%;'>");
    }
    str1.push("<option value='00'> </option>");
    for (var i = 0; i < TrafficType.length; i++) {
        if (TrafficType[i].PhraseID == sData) {
            str1.push("<option value='" + TrafficType[i].PhraseID + "' selected>" + TrafficType[i].PhraseText + "</option>");
        } else {
            str1.push("<option value='" + TrafficType[i].PhraseID + "'>" + TrafficType[i].PhraseText + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format9 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='FlightNum' size='20' maxlength='20' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='FlightNum' size='20' maxlength='20' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='FlightNum' size='20' maxlength='20' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' name='FlightNum' size='20' maxlength='20' style='width:95%;'>";
        }
    }
}
var format10 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='IsSignIn' style='width:95%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='IsSignIn' style='width:95%;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='0'>否</option>");
        str1.push("<option value='1'>是</option>");
    } else {
        if (sData == "1") {
            str1.push("<option value='1' selected>是</option>");
        } else {
            str1.push("<option value='0' selected>否</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
var format11 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' readonly='readonly' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' name='Explain' size='100' maxlength='100' style='width:95%;'>";
        }
    }
}
var format12 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='IsTrain' style='width:95%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='IsTrain' style='width:95%;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='0'>否</option>");
        str1.push("<option value='1'>是</option>");
    } else {
        if (sData == "1") {
            str1.push("<option value='1' selected>是</option>");
            str1.push("<option value='0'>否</option>");
        } else {
            str1.push("<option value='1' selected>否</option>");
            str1.push("<option value='0'>是</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
//民族
var formatExp1 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='MinZu' style='width:100%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='MinZu' style='width:100%;'>");
    }
    str1.push("<option value='00'> </option>");
    for (var i = 0; i < MinZu.length; i++) {
        if (MinZu[i].PhraseID == sData) {
            str1.push("<option value='" + MinZu[i].PhraseID + "' selected>" + MinZu[i].PhraseValue + "</option>");
        } else {
            str1.push("<option value='" + MinZu[i].PhraseID + "'>" + MinZu[i].PhraseValue + "</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}
//生日
var formatExp2 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" readonly='readonly' onchange='ChangeEvent1(this);' name='ShengRi' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='ShengRi' size='10' maxlength='10' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' readonly='readonly' name='ShengRi' size='10' maxlength='10' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' name='ShengRi' size='10' maxlength='10' style='width:95%;'>";
        }
    }
}
//邮箱
var formatExp3 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" readonly='readonly' onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" readonly='readonly' onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' name='YouXiang' size='50' maxlength='50' style='width:95%;'>";
        }
    }
}
//手机
var formatExp4 = function (elCell, oRecord, oColumn, sData) {
    if (sData == "" || sData == null || sData == "null") {
        if (OperStatus != "1" && flag != "0" && flag != "2") {
            elCell.innerHTML = "<input type=\"text\" value=\"\" readonly='readonly' onchange='ChangeEvent1(this);' size='12' maxlength='12' name='ShouJi' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"\" onchange='ChangeEvent1(this);' size='12' maxlength='12' name='ShouJi' style='width:95%;'>";
        }
    } else {
        if (view == "" || view == "check" || view == "state") {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" readonly='readonly' onchange='ChangeEvent1(this);' size='12' maxlength='12' name='ShouJi' style='width:95%;'>";
        } else {
            elCell.innerHTML = "<input type=\"text\" value=\"" + sData + "\" onchange='ChangeEvent1(this);' size='12' maxlength='12' name='ShouJi' style='width:95%;'>";
        }
    }
}
//是否改期
var formatExp5 = function (elCell, oRecord, oColumn, sData) {
    var str1 = [];
    var id = "id" + Math.random();
    str1.push("<option value='00'> </option>");
    if (view == "check") {
        str1.push("<select id='" + id + "' disabled='disabled' name='IsGaiQi' style='width:95%;'>");
    } else {
        str1.push("<select id='" + id + "' onchange='ChangeEvent1(this);' name='IsGaiQi' style='width:95%;'>");
    }
    str1.push("<option value='00'> </option>");
    if (sData == "" || sData == null) {
        str1.push("<option value='0'>否</option>");
        str1.push("<option value='1'>是</option>");
    } else {
        if (sData == "1") {
            str1.push("<option value='1' selected>是</option>");
            str1.push("<option value='0'>否</option>");
        } else {
            str1.push("<option value='1' selected>否</option>");
            str1.push("<option value='0'>是</option>");
        }
    }
    str1.push("</select>");
    elCell.innerHTML = str1.join("");
}

YAHOO.util.Event.addListener(window, "load", function () {
    BindData();
    hideCol();
});
var BindData = function () {
    YAHOO.example.InlineCellEditing = function () {
        var myColumnDefs1 = [
        { key: "MajorStudentID", label: "MajorStudentID", resizeable: true },
        { key: "ClassName", label: "学员姓名", resizeable: true, formatter: format1, width: 80 },
        { key: "IDCard", label: "身份证", resizeable: true, formatter: format2, width: 140 },
        { key: "IsTrain", label: "是否复训", resizeable: true, formatter: format12, width: 60 },
        { key: "Sex", label: "性别", resizeable: true, formatter: format3, width: 60 },
        { key: "Post", label: "职务", resizeable: true, formatter: format4, width: 80 },
        { key: "IsDecision", label: "是否决策人", resizeable: true, formatter: format5, width: 60 },
        { key: "ArriveatTime", label: "到达日期", resizeable: true, formatter: format6, width: 100
        },
        { key: "HouseType", label: "房型", resizeable: true, formatter: format7, width: 80 },
        { key: "IsGaiQi", label: "是否改期", resizeable: true, formatter: formatExp5, width: 60 },
        { key: "ShengRi", label: "生日", resizeable: true, formatter: formatExp2, width: 100
        },
        { key: "YouXiang", label: "邮箱", resizeable: true, formatter: formatExp3, width: 100 },
        { key: "ShouJi", label: "手机", resizeable: true, formatter: formatExp4, width: 90 },
        { key: "MinZu", label: "民族", resizeable: true, formatter: formatExp1, width: 100 },
        { key: "TrafficType", label: "交通方式", resizeable: true, formatter: format8, width: 60 },
        { key: "FlightNum", label: "航班号", resizeable: true, formatter: format9, width: 80 },
        { key: "IsSignIn", label: "是否签到", resizeable: true, formatter: format10, width: 80 },
        { key: "Explain", label: "备注", resizeable: true, formatter: format11, width: 150 }
        ];
        myDataSource1 = new YAHOO.util.DataSource([{ MajorStudentID: "", ClassName: "", IDCard: "", IsTrain: "",
            Sex: "", Post: "", IsDecision: "", ArriveatTime: "", HouseType: "", TrafficType: "", FlightNum: "",
            IsSignIn: "", Explain: "", MinZu: "", ShengRi: "", YouXiang: "", ShouJi: "", IsGaiQi: ""
        }]);
        myDataSource1.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource1.responseSchema = {
            fields: ["MajorStudentID", "ClassName", "IDCard", "IsTrain", "Sex", "Post", "IsDecision",
                "ArriveatTime", "HouseType", "TrafficType", "FlightNum", "IsSignIn", "Explain",
                "MinZu", "ShengRi", "YouXiang", "ShouJi", "IsGaiQi"]
        };
        var myDataTable1 = new YAHOO.widget.ScrollingDataTable("con_1", myColumnDefs1,
                            myDataSource1, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable1 = myDataTable1;
        var i1 = 1,
        bReverseSorted1 = false;
        var trackReverseSorts1 = function (oArg) {
            bReverseSorted1 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        var onEventSaveCellEditor = function (oArgs) {
            SetValueDate(oArgs.newData);
        }
        var SetValueDate = function (val) {
            var oDT = this,
                oConfig = oDT.get("dateOptionsExtend");
            var newData = YAHOO.util.Date.format(val, oConfig, oConfig.locale);
            setValue1(oArgs.editor._oColumn.key, newData);
        }
        myDataTable1.subscribe("rowMouseoverEvent", myDataTable1.onEventHighlightRow);
        myDataTable1.subscribe("rowMouseoutEvent", myDataTable1.onEventUnhighlightRow);
        myDataTable1.subscribe("cellClickEvent", myDataTable1.onEventShowCellEditor);
        myDataTable1.subscribe("editorSaveEvent", onEventSaveCellEditor);
        myDataTable1.subscribe("rowClickEvent", myDataTable1.onEventSelectRow);
        myDataTable1.subscribe("rowDblclickEvent", onRowDoubleClickStudent);
        myDataTable1.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue1();
        return {
            ds: myDataSource1,
            dt: myDataTable1
        };
    } ();
}

//双击查看学员签到信息
var onRowDoubleClickStudent = function () {
    if (flag != "0") {
        var recordID = mDataTable1.getSelectedRows()[0];
        var record = mDataTable1.getRecord(recordID);
        var sid = record.getData("MajorStudentID");
        if (sid != "") {
            document.getElementById("EditUIWindow1").src = "DeliverMajorStudentInfo.aspx?r=" + Math.random() + "&id=" + sid + "";
            YAHOO.example.container.dialog1.show();
        } 
    }
}

var GetFormValue1 = function () {
    for (var i = 0; i < DeliverMajorInfo.length; i++) {
        SetFormValue1(DeliverMajorInfo);
    }
}
var SetFormValue1 = function (obj) {
    var arr = eval(obj);
    myDataSource1.liveData = arr;
    mDataTable1.getDataSource().sendRequest(null, { success: mDataTable1.onDataReturnInitializeTable }, mDataTable1);
}

//隐藏/栏位
function hideCol() {
    mDataTable1.hideColumn(parseInt(0)); mDataTable1.refreshView();
    mDataTable1.hideColumn(parseInt(16)); mDataTable1.refreshView();
    if (flag == "0" || view == "c") {
        mDataTable1.hideColumn(parseInt(9)); mDataTable1.refreshView();
    } else {
        mDataTable1.showColumn(parseInt(9)); mDataTable1.refreshView();
    }
}
//值改变事件
var ChangeEvent1 = function (oArgs) {
    var f = oArgs.name;
    var v = oArgs.value.replace(/\s/g, "");
    setValue1(f, v);
}
//f=字段名 v=值
var setValue1 = function (f, v) {
    var recordID = mDataTable1.getSelectedRows()[0];
    var record = mDataTable1.getRecord(recordID);
    record._oData[f] = v;
    if (f == "ClassName") {
        var sTmp;
        for (var i = 0; i < v.length; i++) {
            sTmp = v.substring(i, i + 1);
            if ((v.charCodeAt(i) > 96 && v.charCodeAt(i) < 123) || (v.charCodeAt(i) > 64 && v.charCodeAt(i) < 91) || (v.charCodeAt(i) > 256)) {
            } else {
                alert("学员姓名不能包含特殊字符!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ClassName]")[0]).val("");
                record._oData["ClassName"] = "";
                return;
            }
        }
    }
    if (f == "IDCard") {
        var num = v;
        var factorArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
        var error;
        var varArray = new Array();
        var intValue;
        var lngProduct = 0;
        var intCheckDigit;
        var intStrLen = num.length;
        var idNumber = num;
        // initialize
        if ((intStrLen != 15) && (intStrLen != 18)) {
            error = "输入身份证号码长度不对！";
            alert(error);
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
            record._oData["IDCard"] = "";
            return false;
        }
        // check and set value
        for (i = 0; i < intStrLen; i++) {
            varArray[i] = idNumber.charAt(i);
            if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {
                error = "错误的身份证号码！.";
                alert(error);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            } else if (i < 17) {
                varArray[i] = varArray[i] * factorArr[i];
            }
        }
        if (intStrLen == 18) {
            //check date
            var date8 = idNumber.substring(6, 14);
            if (checkDate(date8) == false) {
                error = "身份证中日期信息不正确！";
                alert(error);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            }
            // calculate the sum of the products
            for (i = 0; i < 17; i++) {
                lngProduct = lngProduct + varArray[i];
            }
            // calculate the check digit
            intCheckDigit = 12 - lngProduct % 11;
            switch (intCheckDigit) {
                case 10:
                    intCheckDigit = 'X';
                    break;
                case 11:
                    intCheckDigit = 0;
                    break;
                case 12:
                    intCheckDigit = 1;
                    break;
            }
            // check last digit
            if (varArray[17].toUpperCase() != intCheckDigit) {
                //error = "身份证效验位错误!...正确为： " + intCheckDigit + ".";
                error = "身份证输入错误!";
                alert(error);
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            }
        }
        else { //length is 15
            //check date
            var date6 = idNumber.substring(6, 12);
            if (checkDate(date6) == false) {
                alert("身份证日期信息有误！");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=IDCard]")[0]).val("");
                record._oData["IDCard"] = "";
                return false;
            }
        }
        return true;
    }
    if (f == "Post") {
        var sTmp;
        for (var i = 0; i < v.length; i++) {
            sTmp = v.substring(i, i + 1);
            if ((v.charCodeAt(i) > 96 && v.charCodeAt(i) < 123) || (v.charCodeAt(i) > 64 && v.charCodeAt(i) < 91) || (v.charCodeAt(i) > 256)) {
            }
            else {
                alert("职务不能包含特殊字符!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=Post]")[0]).val("");
                record._oData["Post"] = "";
                return;
            }
        }
    }
    if (f == "ArriveatTime" || f == "ShengRi") {
        var myDate = new Date();
        var yy = myDate.getYear();
        if (yy < 1900) yy = yy + 1900;
        var MM = myDate.getMonth() + 1;
        if (MM < 10) MM = '0' + MM;
        var dd = myDate.getDate();
        if (dd < 10) dd = '0' + dd;
        var LocalDate = yy + "-" + MM + "-" + dd + "";
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
        var r = v.match(reg);
        if (r == null) {
            if (f == "ArriveatTime") {
                alert("到达时间格式不正确!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ArriveatTime]")[0]).val(LocalDate);
                //$($($(".yui-dt-selected")[0]).find("input[name=ArriveatTime]")[0]).val(LocalDate);
            }
            if (f == "ShengRi") {
                alert("生日格式不正确!");
                $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ShengRi]")[0]).val(LocalDate);
                //$($($(".yui-dt-selected")[0]).find("input[name=ArriveatTime]")[0]).val(LocalDate);
            }
            setValue1(f, LocalDate);
        }
    }
    if (f == "YouXiang") {
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
        if (!myreg.test(v)) {
            alert("邮箱格式不正确!");
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=YouXiang]")[0]).val("");
            record._oData["YouXiang"] = "";
        }
    }
    if (f == "ShouJi") {
        if (isNaN(v)) {
            alert("手机号必须为数字!");
            $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ShouJi]")[0]).val("");
            record._oData["ShouJi"] = "";
        } else {
            var vlength = v.length;
            if (vlength != 11) {
                if (confirm("您确定您输入的手机号长度为 " + vlength + " 位!")) {

                } else {
                    $($(event.srcElement.parentNode.parentNode.parentNode).find("input[name=ShouJi]")[0]).val("");
                    record._oData["ShouJi"] = "";
                }
                return;
            }
        }
    }
}
var checkDate = function (date) {
    return true;
}
//新增行
var vi = 1;
var handleAdd = function () {
    var TotalCount = $("#Account").val();
    var PayAccount = $("#PayAccount").val();
    var Count = TotalCount - PayAccount;
    if (Count == 0) {
        alert("应交付数量为0,不能添加!");
        return;
    } else {
        if (vi == Count) {
            alert("已达到交付数量最大值,不能添加!");
            return;
        } else {
            var list = mDataTable1.getRecordSet()._records;
            for (var i = 0; i < list.length; i++) {
                if (list[i]._oData.ClassName == "" || list[i]._oData.ClassName == null) {
                    alert("请先填写第" + (i + 1) + "行 学员名称!");
                    return;
                }
                if (list[i]._oData.IDCard == "" || list[i]._oData.IDCard == null) {
                    //alert("请先填写第" + (i + 1) + "行 身份证号!");
                    //return;
                    list[i]._oData.IDCard = "";
                }
                if (list[i]._oData.Sex == "" || list[i]._oData.Sex == "00" || list[i]._oData.Sex == null) {
                    alert("请先填写第" + (i + 1) + "行 性别!");
                    return;
                }
                if (list[i]._oData.Post == "" || list[i]._oData.Post == null) {
                    alert("请先填写第" + (i + 1) + "行 职务!");
                    return;
                }
                if (list[i]._oData.IsDecision == "" || list[i]._oData.IsDecision == "00" || list[i]._oData.IsDecision == null) {
                    alert("请先填写第" + (i + 1) + "行 是否是决策人!");
                    return;
                }
                if (list[i]._oData.ArriveatTime == "" || list[i]._oData.ArriveatTime == null) {
                    alert("请先填写第" + (i + 1) + "行 到达日期!");
                    return;
                }
                if (list[i]._oData.HouseType == "" || list[i]._oData.HouseType == "00" || list[i]._oData.HouseType == null) {
                    alert("请先填写第" + (i + 1) + "行 房型!");
                    return;
                }
            }
            mDataTable1.set("sortedBy", null);
            index = mDataTable1.getRecordSet()._records.length;
            var entity = [{ MajorStudentID: "", ClassName: "", IDCard: "", IsTrain: "",
                Sex: "", Post: "", IsDecision: "", ArriveatTime: "", HouseType: "", TrafficType: "", FlightNum: "",
                IsSignIn: "", Explain: "", MinZu: "", ShengRi: "", YouXiang: "", ShouJi: "", IsGaiQi: ""
            }];
            mDataTable1.addRows(entity, index);
            vi++;
        }
    }
}
//删除行
var handleDelete = function () {
    var recordID = mDataTable1.getSelectedRows()[0];
    if (recordID != null && recordID.length != 1) {
        if (mDataTable1.getRecordSet()._records.length == 1) {
            alert("最后一行不能删除!");
            return;
        } else {
            var MajorId = $('#ID').val();
            record = mDataTable1.getRecord(recordID);
            var vid = record.getData("MajorStudentID");
            if (flag == "0" || vid == "" || vid == "00000000-0000-0000-0000-000000000000") {
                mDataTable1.deleteRow(recordID);
                LoadAccountReceivable();
            } else {
                if (confirm("您确定删除该行吗?")) {
                    var SaveUrl = "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&action=delete&entity=CrmMajorStudent&json=&mid=" + MajorId + "&id=" + vid;
                    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                        success: function (res) {
                            try {
                                var str = res.responseText;
                                if (str == "1") {
                                    mDataTable1.deleteRow(recordID);
                                    vi--;
                                    alert("删除成功!");
                                }
                                else {
                                    alert(str + "\n" + "数据删除失败!");
                                    return;
                                }
                            } catch (e) {
                            }
                            finally {
                            }
                        },
                        failure: function (error) {
                            alert("数据错误：" + error.statusText);
                        }
                    }, null);
                }
            }
        }
    } else {
        alert("请选中一行后删除！");
    }
}
//刷新父窗体数据
function RefreshDataParent() {
    if (parent.NeedRefreshPage != null) {
        if (typeof (parent.NeedRefreshPage.LoadData) == "function") {
            parent.NeedRefreshPage.RefreshData();
        }
    }
}
var setValue = function () {
    instance[0].ID = vid;
    instance[0].Code = $("#Code").val();
    instance[0].OrderProductID = $("#OrderProductID").val();
    instance[0].NegotiateTeach = $("#NegotiateTeach").val();
    instance[0].ClassServer = $("#ClassServer").val();
    instance[0].ClassFrontServer = $("#ClassFrontServer").val();
    instance[0].ProductLayoutID = $("#ProductLayoutID").val();
    instance[0].GradeDeptId = $("#GradeDeptId").val();
    instance[0].ConstDeptId = $("#ConstDeptId").val();
    instance[0].exp3 = $("#exp3").val();  //是否现场完款
    if (flag == "2") { //变更
        if (view == "m") {  //变更重新走流程
            $("#DliverState").get(0).selectedIndex = 2;
        }
        instance[0].DliverState = $("#DliverState").val();
    } else {
        $("#DliverState").get(0).selectedIndex = 2;
        instance[0].DliverState = $("#DliverState").val();
    }
    instance[0].WorkFlowId = WorkFlowId;
    instance[0].WorkTaskId = WorkTaskId;
    instance[0].WorkTaskInsId = $("#WorkTaskInsId").val();
    if (flag == "1" && view != "" && OperStatus == "1") { //退回时允许修改信息
        instance[0].WorkFlowInsId = WorkflowInsId;
    } else {
        instance[0].WorkFlowInsId = $("#WorkFlowInsId").val();
    }
}
//保存
var Save = function () {
    setValue();
    if (instance[0].ID == "" || instance[0].ID == null) {
        alert("数据异常，请刷新页面!");
        $('#txtOrderID').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].Code == "" || instance[0].Code == null) {
        alert("单号不能为空!");
        $('#txtOrderID').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    var ProductList = $("#ProductList").val();
    if (ProductList == "" || ProductList == null) {
        alert("产品列表不能为空!");
        $('#ProductList').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].OrderProductID == "" || instance[0].OrderProductID == null) {
        alert("订单号不能为空!");
        $('#txtOrderID').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].NegotiateTeach == "" || instance[0].NegotiateTeach == null) {
        //alert("谈单老师不能为空!");
        //$('#txtNegotiateTeach').focus();
        //return;
        instance[0].NegotiateTeach = "00000000-0000-0000-0000-000000000000";
    }
    if (instance[0].ClassServer == "" || instance[0].ClassServer == null) {
        alert("课中服务人不能为空!");
        $('#txtClassServer').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].ClassFrontServer == "" || instance[0].ClassFrontServer == null) {
        alert("负责交付人不能为空!");
        $('#txtClassFrontServer').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].ProductLayoutID == "" || instance[0].ProductLayoutID == null) {
        alert("课程规划期数不能为空!");
        $('#txtProductLayoutID').focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].exp3 == "" || instance[0].exp3 == null) {
        alert("是否现场完款不能为空!\n请选择真实的完款情况!");
        $("#exp3").focus();
        if (action == "insert") {
            $("#DliverState").get(0).selectedIndex = 0;
        }
        return;
    }
    if (instance[0].DliverState == "" || instance[0].DliverState == null) {
        //instance[0].DliverState = "00000000-0000-0000-0000-000000000000";
        alert("状态不能为空!");
        $("#DliverState").focus();
        return;
    }
    if (instance[0].ProductLayoutID == "" || instance[0].ProductLayoutID == null) {
        instance[0].ProductLayoutID = "00000000-0000-0000-0000-000000000000";
    }
    if (instance[0].GradeDeptId == "" || instance[0].GradeDeptId == null) {
        instance[0].GradeDeptId = "00000000-0000-0000-0000-000000000000";
    }
    if (instance[0].ConstDeptId == "" || instance[0].ConstDeptId == null) {
        instance[0].ConstDeptId = "00000000-0000-0000-0000-000000000000";
    }
    var list = mDataTable1.getRecordSet()._records;
    var elist = [];
    instance[0].StudentList = "";
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData.MajorStudentID == "" || list[i]._oData.MajorStudentID == null) {
            list[i]._oData.MajorStudentID = "00000000-0000-0000-0000-000000000000";
        }
        if (list[i]._oData.ClassName == "" || list[i]._oData.ClassName == null) {
            alert("第" + (i + 1) + "行 学员名称不能为空!");
            return;
        }
        if (list[i]._oData.IDCard == "" || list[i]._oData.IDCard == null) {
            //alert("第" + (i + 1) + "行 身份证号不能为空!");
            //return;
            list[i]._oData.IDCard = "";
        }
        if (list[i]._oData.IsTrain == "" || list[i]._oData.IsTrain == "00" || list[i]._oData.IsTrain == null) {
            list[i]._oData.IsTrain = "0";
        }
        if (list[i]._oData.Sex == "" || list[i]._oData.Sex == "00" || list[i]._oData.Sex == null) {
            alert("第" + (i + 1) + "行 性别不能为空!");
            return;
        }
        if (list[i]._oData.Post == "" || list[i]._oData.Post == null) {
            alert("第" + (i + 1) + "行 职务不能为空!");
            return;
        }
        if (list[i]._oData.IsDecision == "" || list[i]._oData.IsDecision == "00" || list[i]._oData.IsDecision == null) {
            alert("第" + (i + 1) + "行 是否是决策人不能为空!");
            return;
        }
        if (list[i]._oData.ArriveatTime == "" || list[i]._oData.ArriveatTime == null) {
            alert("第" + (i + 1) + "行 到达日期不能为空!");
            return;
        }
        if (list[i]._oData.HouseType == "" || list[i]._oData.HouseType == "00" || list[i]._oData.HouseType == null) {
            alert("第" + (i + 1) + "行 房型不能为空!");
            return;
        }
        if (list[i]._oData.IsGaiQi == "" || list[i]._oData.IsGaiQi == "00" || list[i]._oData.IsGaiQi == null) {
            list[i]._oData.IsGaiQi = "0";
        }
        if (list[i]._oData.TrafficType == "" || list[i]._oData.TrafficType == "00" || list[i]._oData.TrafficType == null) {
            list[i]._oData.TrafficType = "00000000-0000-0000-0000-000000000000";
        }
        if (list[i]._oData.IsSignIn == "" || list[i]._oData.IsSignIn == "00" || list[i]._oData.IsSignIn == null) {
            list[i]._oData.IsSignIn = "0";
        }
        if (list[i]._oData.Explain == "null" || list[i]._oData.Explain == null) {
            list[i]._oData.Explain = "";
        }
        if (list[i]._oData.FlightNum == "null" || list[i]._oData.FlightNum == null) {
            list[i]._oData.FlightNum = "";
        }
        if (list[i]._oData.MinZu == "null" || list[i]._oData.MinZu == null) {
            list[i]._oData.MinZu = "";
        }
        if (list[i]._oData.ShengRi == "null" || list[i]._oData.ShengRi == null) {
            list[i]._oData.ShengRi = "";
        }
        if (list[i]._oData.YouXiang == "null" || list[i]._oData.YouXiang == null) {
            list[i]._oData.YouXiang = "";
        }
        if (list[i]._oData.ShouJi == "null" || list[i]._oData.ShouJi == null) {
            list[i]._oData.ShouJi = "";
        }

        elist.push(list[i]._oData);
        elist[i].MajorID = $('#ID').val();
        elist[i].FlightNum = list[i]._oData.FlightNum;
        elist[i].Explain = list[i]._oData.Explain;
    }
    for (var j = 0; j < elist.length; j++) {
        var vCustomerId = $("#CustomerId").val();
        var vProductId = $("#ProductId").val();
        if (vCustomerId == "") {
            vCustomerId = "00000000-0000-0000-0000-000000000000";
        }
        if (vProductId == "") {
            vProductId = "00000000-0000-0000-0000-000000000000";
        }
        instance[0].StudentList += "#" + vCustomerId + "︾" + elist[j].MajorStudentID + "︾" + vProductId + "︾" +
                                   $("#ID").val() + "︾" + elist[j].ClassName.replace(/(^\s*)|(\s*$)/g, '') + "︾" + elist[j].IDCard + "︾" +
                                   elist[j].Sex + "︾" + elist[j].Post.replace(/(^\s*)|(\s*$)/g, '') + "︾" + elist[j].IsDecision + "︾" +
                                   elist[j].ArriveatTime + "︾" + elist[j].HouseType + "︾" + elist[j].TrafficType + "︾" +
                                   elist[j].FlightNum + "︾" + elist[j].IsSignIn + "︾" + elist[j].Explain + "︾" +
                                   elist[j].MinZu + "︾" + elist[j].ShengRi + "︾" + elist[j].YouXiang + "︾" +
                                   elist[j].ShouJi + "︾" + elist[j].IsTrain + "︾" + elist[j].IsGaiQi + "︾";
    }
    if (flag == "1" && view != "" && OperStatus == "1") { //退回时允许修改信息
        action = "update";
    }
    var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
    $("#jsonDataContent").val(json);
    if (flag == "2") {
        if (confirm("您确定修改当前公开课信息吗?")) {
            trySave();
        }
    } else {
        if (confirm("您确定保存当前公开课信息吗?")) {
            trySave();
        }
    }
}
function trySave() {
    var url = "../../Extend/AjaxData/CustomOperating.aspx?action=" + action + "&cName=" + encodeURI($("#CustomerName").val()) + "&flag=1&oid=" + OperatorInstanceId + "&entity=" + entity + "";
    if (flag == "2" && view == "m") {
        url = "../../Extend/AjaxData/CustomOperating.aspx?action=" + action + "&cName=" + encodeURI($("#CustomerName").val()) + "&flag=1&view=m&oid=" + OperatorInstanceId + "&entity=" + entity + "";
    } else if (flag == "2" && view == "c") { 
        url = "../../Extend/AjaxData/CustomOperating.aspx?action=" + action + "&cName=" + encodeURI($("#CustomerName").val()) + "&flag=1&view=c&oid=" + OperatorInstanceId + "&entity=" + entity + "";
    } else if (flag == "2" && view == "state") {
        url = "../../Extend/AjaxData/CustomOperating.aspx?action=" + action + "&cName=" + encodeURI($("#CustomerName").val()) + "&flag=1&view=state&oid=" + OperatorInstanceId + "&entity=" + entity + "";
    }
    var formObject = document.getElementById('form2');
    YAHOO.util.Connect.setForm(formObject);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', url, callback);
}
var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        RefreshDataParent();
        if (str == "1") {
            if (flag == "1" && view != "" && OperStatus == "1") { //退回时允许修改信息
                window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
            } else {
                window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
            }
        } else if (str == "2") {
            if (flag == "2" && view == "m") { //变更重走流程
                window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
            } else {
                alert("数据保存成功!");
                Close();
            }
        } else {
            alert(str + "\n数据保存失败!");
        }
    } catch (e) {
    }
    finally {
    }
}
var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};

//保存产品期数 提交
var Save1 = function (obj) {
    var ProductLayoutID = $("#ProductLayoutID").val();
    if (ProductLayoutID == "" || ProductLayoutID == "00000000-0000-0000-0000-000000000000" || ProductLayoutID == null) {
        alert("产品期数不能为空!");
        return;
    } else {
        var adduser = $("#AddUser").val();
        var addtime = $("#txtAddTime").val();
        var orderId = $("#OrderID").val();
        if (view == "") {  //正常提交
            if (adduser == "") {
                alert("填写人不能为空!");
                return;
            }
        } else {
            adduser = "00000000-0000-0000-0000-000000000000";
            addtime = "1900-01-01";
        }
        if (obj == "0") {
            if (confirm("您确定提交?")) {
                Submit(orderId, adduser, addtime, ProductLayoutID, obj);
            }
        } else {
            Submit(orderId, adduser, addtime, ProductLayoutID, obj);
        }
    }
}
var Submit = function (orderId, adduser, addtime, ProductLayoutID, obj) {
    var SaveUrl = "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&action=update&entity=CrmDeliverMajors" +
                        "&orderId=" + orderId + "&adduser=" + adduser + "&addtime=" + addtime + "&pid=" + ProductLayoutID +
                        "&id=" + vid + "&oid=" + OperatorInstanceId + "&tid=" + WorkflowInsId;
    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    RefreshDataParent();
                    if (obj == "0") {
                        window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
                    }
                } else {
                    alert(str);
                    return;
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}


//退回
var Back = function () {
    var vMessage = $("#txtReturn").val();
    if (confirm("您确定退回?")) {
        var SaveUrl = "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&action=check&entity=CrmDeliverMajorUnAgree&msg=" + encodeURI(vMessage) + "" +
            "&OperatorInstanceId=" + OperatorInstanceId + "&WorkflowId=" + WorkFlowId + "&WorktaskId=" + WorkTaskId + "&WorkflowInsId=" + WorkflowInsId + "&WorktaskInsId=" + WorkTaskInsId + "";
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        YAHOO.example.container.dialog2.hide();
                        window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
                    } else {
                        alert(str);
                        return;
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
}

var setControlDisabled = function (obj) {
    if (obj == 1) {
        $("#btnOrderProductID").hide();
        $("#btnGradeDeptId").hide();
        $("#btnConstDeptId").hide();
        $("#btnNegotiateTeach").hide();
        $("#btnClassFrontServer").hide();
        $("#btnClassServer").hide();
        $("#btnClassServer").hide();
        $("#btnOrderID").hide();
        $("#btnProductLayoutID").hide();
        var obj = document.getElementById("fieldForm"); //得到DIV对象
        var s = obj.getElementsByTagName("select");
        var e = obj.getElementsByTagName("input");
        for (var j = 0; j < s.length; j++) {
            s[j].disabled = true;
        }
        for (var i = 0; i < e.length; i++) {
            $("#" + e[i].id + "").attr("readonly", "readonly");
        }
        var trs = $("#table1 tr");
        if (view == "check" || Descript == "ck") {
            for (var i = 0; i < trs.length; i++) {
                trs[i].style.display = "none";
            }
        } else {
            trs[0].style.display = "block";
            trs[1].style.display = "none";
        }
    }
    if (obj == 2) {  //退回时允许修改信息
        var obj = document.getElementById("fieldForm"); //得到DIV对象
        var s = obj.getElementsByTagName("select");
        var e = obj.getElementsByTagName("input");
        for (var j = 0; j < s.length; j++) {
            if (s[j].id == "DliverState") {
                s[j].disabled = true;
            }
        }
        $("#btnOrderID").hide();
    }
}

